package com.yanqu.road.server.manger.activity.springunionbanquet;

import com.yanqu.road.dao.impl.activity.springunionbanquet.SpringUnionBanquetConfigDaoImpl;
import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.springunionbanquet.config.SpringUnionBanquetConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.springunionbanquet.SpringUnionBanquetModule;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;

import java.util.List;
import java.util.Map;

public class SpringUnionBanquetMgr extends TempMgr {

    private static SpringUnionBanquetConfig config;

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    public static void reloadActivityData() {
        getLogger().info("reload SpringUnionBanquet Activity start");

        List<ActivityInfo> openActivityInfoList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.SpringUnionBanquet.getValue());
        if (openActivityInfoList.isEmpty()) {
            getLogger().info("no SpringUnionBanquet Activity in show time");
            config = null;

        } else {

            ActivityInfo activityInfo = openActivityInfoList.get(0);
            SpringUnionBanquetConfig banquetConfig = new SpringUnionBanquetConfig(activityInfo);

            int tmpActivityId = activityInfo.getActivityId();
            banquetConfig.setAwardInfoList(new SpringUnionBanquetConfigDaoImpl().getSpringUnionBanquetAwardInfoList(tmpActivityId));

            //初始化配置
            Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(tmpActivityId);
            banquetConfig.init(activityConfigMap);
            config = banquetConfig;
        }

        for (GamePlayer player : GamePlayerMgr.getAllOnlinePlayer()) {
            player.getModule(SpringUnionBanquetModule.class).afterLogin();
        }

        getLogger().info("reload SpringUnionBanquet Activity finish");
    }

    public static SpringUnionBanquetConfig getConfig() {
        return config;
    }

    public static ActivityInfo getActivityInfo(){
        if(config == null){
            return null;
        }
        return config.getActivityInfo();
    }
}
